<script>
import baseUrl from './utils/globalUrl.js';

export default {
  data() {
    return {
      resAmap: null,
      map: null
    };
  },
  methods: {
    // 获取天气数据
    getWeather(result) {
      const parameters = `?city=${result.adcode}&key=${baseUrl.gdKey}&output=JSON`;
      this.$axios.get(`${baseUrl.gdUrl}${parameters}`)
        .then((response) => {
          // 存储天气信息
          const weatherInfo = response.data.lives[0];
          // this.globalWeather.data = weatherInfo;

          uni.setStorage({
            key: 'weatherinfo',
            data: JSON.stringify(weatherInfo)
          });
        })
        .catch(function(error) {
          console.log(error);
        });
    }
  },
  onLaunch: async function() {
    setTimeout(() => {
      uni.setTabBarBadge({
        index: 1,
        text: '20'
      });
      uni.showTabBarRedDot({
        index: 3
      });
    }, 1000);

    // 只有在h5 当中使用
    // #ifdef H5
    // this.resAmap = await mapLoader();
    this.$nextTick(() => {
      // 获取定位
      this.$axios.get(`https://restapi.amap.com/v3/ip?&output=JSON&key=${baseUrl.gdKey}`)
        .then((response) => {
          // console.log(this);
          if (response.status === 200) {
            this.getWeather(response.data);
          }
        })
        .catch(function(error) {
          console.log(error);
        });
    });
    // #endif
  },
  onHide: function() {}
};
</script>

<style lang="scss">
	page {
		background-color: #F5F7FA;

	}
  .bottomTips {
    color: #b8b8b8;
    font-size: 14px !important;
    &::before {
      margin-right: 10px;
    }

    &::after {
      margin-left: 10px;
    }

    &::after,
    &::before {
      content: '';
      width: 80px;
      height: 1px;
      position: relative;
      top: 1px;
      border-top: 1px solid rgb(238, 233, 233);
    }

  }

	/*每个页面公共css */
	/* 注意要写在第一行，同时给style标签加入lang="scss"属性 */
	@import "uview-ui/index.scss";
	@import './static/iconfont.css'

</style>

